﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADONETDataServicesExtension.Utils;

namespace ADONETDataServicesExtension
{
    public class DataServiceException : FrameworkEncapsulatedType<Exception>
    {
        internal const string FrameworkTypeName = "System.Data.Services.DataServiceException";

        public DataServiceException(Exception dataServiceException)
            : base(dataServiceException)
        {
        }

        public void Throw()
        {
            throw FrameworkObject;
        }

        public static DataServiceException CreateBadRequestError(string message)
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeStaticMethod<Exception>(FrameworkTypeName, "CreateBadRequestError", message), frameworkValue => new DataServiceException(frameworkValue));
        }

        public static DataServiceException CreateSyntaxError()
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeStaticMethod<Exception>(FrameworkTypeName, "CreateSyntaxError"), frameworkValue => new DataServiceException(frameworkValue));
        }

        public static DataServiceException CreateSyntaxError(string message)
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeStaticMethod<Exception>(FrameworkTypeName, "CreateSyntaxError", message), frameworkValue => new DataServiceException(frameworkValue));
        }

        public static DataServiceException CreateMethodNotAllowed(string message, string allow)
        {
            return ReflectionHelper.Convert(ReflectionHelper.InvokeStaticMethod<Exception>(FrameworkTypeName, "CreateMethodNotAllowed", message, allow), frameworkValue => new DataServiceException(frameworkValue));
        }
    }
}
